package com.liu.common.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.liu.common.content.RedisKeyInterface;
import com.liu.common.entity.dto.WfDictDTO;
import com.liu.common.entity.vo.*;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 对git项目https://github.com/WsureWarframe/warframe-info-api/的对接
 */
@Slf4j
public class WIAClientUtils {

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    private static RedisTemplate<String, String> staticRedisTemplate;

    @PostConstruct
    public void init() {
        staticRedisTemplate = redisTemplate;
    }

    public static void main(String[] args) throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        File file = new File("src/main/resources/dict/simplify_i18n.json");
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        StringBuilder WF_DICT = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            WF_DICT.append(line);
        }
        List<WfDictDTO> wfDictDTOS = JSONUtil.parseArray(WF_DICT.toString()).toList(WfDictDTO.class);
        List<String> wfDistDTOEnList = wfDictDTOS.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOS.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        JSONObject baseJson = getBaseJson();
        List<WIASyndicateMissionVO> syndicateMissions = baseJson.getJSONArray("syndicateMissions").toList(WIASyndicateMissionVO.class);
        WIASyndicateMissionVO wiaSyndicateMissionVO = syndicateMissions.stream().filter(w -> w.getSyndicate().equals("Ostrons")).findFirst().get();
        initTranslateAll(wiaSyndicateMissionVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaSyndicateMissionVO.setActivation(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaSyndicateMissionVO.setExpiry(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaSyndicateMissionVO.setEta(s);
        System.out.println(wiaSyndicateMissionVO);
    }

    /**
     * 递归反射翻译实体类全部字段（包括内部类）
     * @param object object
     * @param wfDistDTOEnList wfDistDTOEnList
     * @param wfDistDTOZhMap wfDistDTOZhMap
     * @throws IllegalAccessException 抛出异常
     */
    public static void initTranslateAll(Object object, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException {
        Class<?> aClass = object.getClass();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            Object o2 = declaredField.get(object);
            if (Objects.isNull(o2)) {
                continue;
            }
            if (declaredField.getType() == String.class) {
                String o = (String) declaredField.get(object);
                String declaredFieldName = declaredField.getName();
                if (declaredFieldName.equals("tier") && o.equals("Lith")) {
                    declaredField.set(object, "古纪");
                } else {
                    if (wfDistDTOEnList.contains(o)) {
                        declaredField.set(object, wfDistDTOZhMap.get(o));
                    } else {
                        for (String en : wfDistDTOEnList) {
                            if (o.contains(en)) {
                                o = o.replaceAll(en, wfDistDTOZhMap.get(en));
                                declaredField.set(object, o);
                            }
                        }
                    }
                }
            } else if (declaredField.getType() == List.class) {
                List list = (List) declaredField.get(object);
                Iterator listIterator = list.iterator();
                List<Object> addList = new ArrayList<>();
                while (listIterator.hasNext()) {
                    Object o = listIterator.next();
                    if (o instanceof String o1) {
                        if (wfDistDTOEnList.contains(o)) {
                            o1 = wfDistDTOZhMap.get(o);
                        } else {
                            for (String en : wfDistDTOEnList) {
                                if (o1.contains(en)) {
                                    o1 = o1.replaceAll(en, wfDistDTOZhMap.get(en));
                                }
                            }
                        }
                        addList.add(o1);
                        listIterator.remove();
                    } else if (o instanceof Integer) {
                    } else {
                        initTranslateAll(o, wfDistDTOEnList, wfDistDTOZhMap);
                    }
                }
                if (CollUtil.isNotEmpty(addList)) {
                    list.addAll(addList);
                }
            } else if (declaredField.getType() == Boolean.class || declaredField.getType() == Integer.class){

            } else {
                initTranslateAll(o2, wfDistDTOEnList, wfDistDTOZhMap);
            }
        }
    }

    /**
     * 获取基础JSON
     * @return JSONObject
     */
    private static JSONObject getBaseJson() {
        String wia = staticRedisTemplate.opsForValue().get(RedisKeyInterface.WIA);
        if (wia != null) {
            return JSONUtil.parseObj(wia);
        } else {
            String url = "https://api.warframestat.us/pc/";
            String body = HttpRequest.get(url)
                    .timeout(60000)
                    .execute()
                    .body();
            staticRedisTemplate.opsForValue().set(RedisKeyInterface.WIA, body, 5, TimeUnit.MINUTES);
            return JSONUtil.parseObj(body);
        }
    }

    /**
     * 获取基础字典
     * @return List<WfDistDTO>
     * @throws IOException 抛出异常
     */
    private static List<WfDictDTO> getDist() throws IOException {
//        //运行测试类时使用
//        byte[] bytes1 = FileUtil.readBytes(new File("src/main/resources/dict/simplify_i18n_all.json"));
//        String jsonContent = new String(bytes1, StandardCharsets.UTF_8);
//        return JSONUtil.parseArray(jsonContent).toList(WfDictDTO.class);
        try (InputStream inputStream = WIAClientUtils.class.getClassLoader().getResourceAsStream("/dict/simplify_i18n_all.json")) {
            if (inputStream == null) {
                throw new RuntimeException("文件不存在");
            }
            byte[] bytes = inputStream.readAllBytes();
            String jsonContent = new String(bytes, StandardCharsets.UTF_8);
            return JSONUtil.parseArray(jsonContent).toList(WfDictDTO.class);
        }
    }

    /**
     * 获取活动
     * @return List<WIAGetEventsVO>
     * @throws IOException 抛出异常
     * @throws IllegalAccessException 抛出异常
     */
    public static List<WIAGetEventsVO> getEvents() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIAGetEventsVO> wiaGetEventsVOList = baseJson.getJSONArray("events").toList(WIAGetEventsVO.class);
        for (WIAGetEventsVO wiaGetEventsVO : wiaGetEventsVOList) {
            initTranslateAll(wiaGetEventsVO, wfDistDTOEnList, wfDistDTOZhMap);
            wiaGetEventsVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetEventsVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
            wiaGetEventsVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetEventsVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetEventsVO.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetEventsVO.setEta(s);
        }
        return wiaGetEventsVOList;
    }

    /**
     * 获取警报
     * @return String
     */
    public static List<WIAGetAlertsVO> getAlerts() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIAGetAlertsVO> wiaGetAlertsVOList = baseJson.getJSONArray("alerts").toList(WIAGetAlertsVO.class);
        for (WIAGetAlertsVO wiaGetAlertsVO : wiaGetAlertsVOList) {
            initTranslateAll(wiaGetAlertsVO, wfDistDTOEnList, wfDistDTOZhMap);
            wiaGetAlertsVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetAlertsVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
            wiaGetAlertsVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetAlertsVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetAlertsVO.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetAlertsVO.setEta(s);
        }
        return wiaGetAlertsVOList;
    }

    /**
     * 获取突击
     * @return String
     */
    public static WIAGetSortieVO getSortie() throws IllegalAccessException, IOException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetSortieVO wiaGetSortieVO = baseJson.getJSONObject("sortie").toBean(WIAGetSortieVO.class);
        initTranslateAll(wiaGetSortieVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetSortieVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetSortieVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetSortieVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetSortieVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetSortieVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetSortieVO.setEta(s);
        return wiaGetSortieVO;
    }

    /**
     * 获取地球赏金
     * @return String
     */
    public static WIASyndicateMissionVO getOstrons() throws IOException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIASyndicateMissionVO> wiaSyndicateMissionVOList = baseJson.getJSONArray("syndicateMissions").toList(WIASyndicateMissionVO.class);
        WIASyndicateMissionVO wiaSyndicateMissionVO = wiaSyndicateMissionVOList.stream().filter(w -> w.getSyndicate().equals("Ostrons")).findFirst().get();
        initTranslateAll(wiaSyndicateMissionVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaSyndicateMissionVO.setActivation(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaSyndicateMissionVO.setExpiry(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaSyndicateMissionVO.setEta(s);
        return wiaSyndicateMissionVO;
    }

    /**
     * 获取金星赏金
     * @return String
     */
    public static WIASyndicateMissionVO getSolaris() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIASyndicateMissionVO> wiaSyndicateMissionVOList = baseJson.getJSONArray("syndicateMissions").toList(WIASyndicateMissionVO.class);
        WIASyndicateMissionVO wiaSyndicateMissionVO = wiaSyndicateMissionVOList.stream().filter(w -> w.getSyndicate().equals("Solaris United")).findFirst().get();
        initTranslateAll(wiaSyndicateMissionVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaSyndicateMissionVO.setActivation(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaSyndicateMissionVO.setExpiry(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaSyndicateMissionVO.setEta(s);
        return wiaSyndicateMissionVO;
    }

    /**
     * 获取火卫二赏金
     * @return String
     */
    public static WIASyndicateMissionVO getEntratiSyndicate() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIASyndicateMissionVO> wiaSyndicateMissionVOList = baseJson.getJSONArray("syndicateMissions").toList(WIASyndicateMissionVO.class);
        WIASyndicateMissionVO wiaSyndicateMissionVO = wiaSyndicateMissionVOList.stream().filter(w -> w.getSyndicate().equals("Entrati")).findFirst().get();
        initTranslateAll(wiaSyndicateMissionVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaSyndicateMissionVO.setActivation(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaSyndicateMissionVO.setExpiry(DateUtil.format(DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaSyndicateMissionVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaSyndicateMissionVO.setEta(s);
        return wiaSyndicateMissionVO;
    }

    /**
     * 获取裂缝
     * @return String
     */
    public static List<WIAGetFissuresVO> getFissures() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIAGetFissuresVO> wiaGetFissuresVOList = baseJson.getJSONArray("fissures").toList(WIAGetFissuresVO.class);
        for (WIAGetFissuresVO wiaGetFissuresVO : wiaGetFissuresVOList) {
            initTranslateAll(wiaGetFissuresVO, wfDistDTOEnList, wfDistDTOZhMap);
            wiaGetFissuresVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetFissuresVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
            wiaGetFissuresVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetFissuresVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetFissuresVO.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetFissuresVO.setEta(s);
        }
        return wiaGetFissuresVOList;
    }

    /**
     * 获取奸商
     * @return String
     */
    public static WIAGetVoidTraderVO getVoidTrader() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetVoidTraderVO wiaGetVoidTraderVO = baseJson.getJSONObject("voidTrader").toBean(WIAGetVoidTraderVO.class);
        initTranslateAll(wiaGetVoidTraderVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetVoidTraderVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetVoidTraderVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetVoidTraderVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetVoidTraderVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        if (wiaGetVoidTraderVO.getActive()) {
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetVoidTraderVO.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetVoidTraderVO.setEta(s);
        } else {
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetVoidTraderVO.getActivation()), BetweenFormatter.Level.SECOND);
            wiaGetVoidTraderVO.setEta(s);
        }
        return wiaGetVoidTraderVO;
    }

    /**
     * 获取中继站优惠（每日特惠）
     * @return String
     */
    public static List<WIAGetDailyDealsVO> getDailyDeals() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIAGetDailyDealsVO> wiaGetDailyDealsVOList = baseJson.getJSONArray("dailyDeals").toList(WIAGetDailyDealsVO.class);
        for (WIAGetDailyDealsVO wiaGetDailyDealsVO : wiaGetDailyDealsVOList) {
            initTranslateAll(wiaGetDailyDealsVO, wfDistDTOEnList, wfDistDTOZhMap);
            wiaGetDailyDealsVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetDailyDealsVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
            wiaGetDailyDealsVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetDailyDealsVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetDailyDealsVO.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetDailyDealsVO.setEta(s);
        }
        return wiaGetDailyDealsVOList;
    }

    /**
     * 获取所有平原时间
     * @return Map<String, Object>
     * @throws IOException
     * @throws ClassNotFoundException
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     * @throws NoSuchMethodException
     */
    public static Map<String, Object> getCycle() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetEarthCycleVO wiaGetEarthCycleVO = getEarthCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        WIAGetCetusCycleVO wiaGetCetusCycleVO = getCetusCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        WIAGetVallisCycleVO wiaGetVallisCycleVO = getVallisCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        WIAGetCambionCycleVO wiaGetCambionCycleVO = getCambionCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        WIAGetZarimanCycleVO wiaGetZarimanCycleVO = getZarimanCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        WIAGetDuviriCycleVO wiaGetDuviriCycleVO = getDuviriCycle(baseJson, wfDistDTOEnList, wfDistDTOZhMap);
        Map<String, Object> templateParam = new HashMap<>();
        templateParam.put("wiaGetEarthCycleVO", wiaGetEarthCycleVO);
        templateParam.put("wiaGetCetusCycleVO", wiaGetCetusCycleVO);
        templateParam.put("wiaGetVallisCycleVO", wiaGetVallisCycleVO);
        templateParam.put("wiaGetCambionCycleVO", wiaGetCambionCycleVO);
        templateParam.put("wiaGetZarimanCycleVO", wiaGetZarimanCycleVO);
        templateParam.put("wiaGetDuviriCycleVO", wiaGetDuviriCycleVO);
        return templateParam;
    }

    /**
     * 获取地球时间
     * @return String
     */
    public static WIAGetEarthCycleVO getEarthCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetEarthCycleVO wiaGetEarthCycleVO = baseJson.getJSONObject("earthCycle").toBean(WIAGetEarthCycleVO.class);
        initTranslateAll(wiaGetEarthCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetEarthCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetEarthCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetEarthCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetEarthCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetEarthCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetEarthCycleVO.setEta(s);
        if (wiaGetEarthCycleVO.getState().equals("白天")) {
            wiaGetEarthCycleVO.setNextState("夜晚");
        } else {
            wiaGetEarthCycleVO.setNextState("白天");
        }
        return wiaGetEarthCycleVO;
    }

    /**
     * 获取地球平原时间
     * @return String
     */
    public static WIAGetCetusCycleVO getCetusCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetCetusCycleVO wiaGetCetusCycleVO = baseJson.getJSONObject("cetusCycle").toBean(WIAGetCetusCycleVO.class);
        initTranslateAll(wiaGetCetusCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetCetusCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetCetusCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetCetusCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetCetusCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetCetusCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetCetusCycleVO.setEta(s);
        if (wiaGetCetusCycleVO.getIsDay()) {
            wiaGetCetusCycleVO.setNextState("夜晚");
        } else {
            wiaGetCetusCycleVO.setNextState("白天");
        }
        return wiaGetCetusCycleVO;
    }

    /**
     * 获取金星平原时间
     * @return String
     */
    public static WIAGetVallisCycleVO getVallisCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetVallisCycleVO wiaGetVallisCycleVO = baseJson.getJSONObject("vallisCycle").toBean(WIAGetVallisCycleVO.class);
        initTranslateAll(wiaGetVallisCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetVallisCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetVallisCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetVallisCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetVallisCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetVallisCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetVallisCycleVO.setEta(s);
        if (wiaGetVallisCycleVO.getIsWarm()) {
            wiaGetVallisCycleVO.setNextState("寒冷");
        } else {
            wiaGetVallisCycleVO.setNextState("温暖");
        }
        return wiaGetVallisCycleVO;
    }

    /**
     * 获取火卫二平原时间
     * @return String
     */
    public static WIAGetCambionCycleVO getCambionCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetCambionCycleVO wiaGetCambionCycleVO = baseJson.getJSONObject("cambionCycle").toBean(WIAGetCambionCycleVO.class);
        initTranslateAll(wiaGetCambionCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetCambionCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetCambionCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetCambionCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetCambionCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetCambionCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetCambionCycleVO.setEta(s);
        if (wiaGetCambionCycleVO.getState().equals("fass")) {
            wiaGetCambionCycleVO.setState("Fass");
            wiaGetCambionCycleVO.setNextState("Vome");
        } else {
            wiaGetCambionCycleVO.setState("Vome");
            wiaGetCambionCycleVO.setNextState("Fass");
        }
        return wiaGetCambionCycleVO;
    }

    /**
     * 获取扎里曼平原时间
     * @return String
     */
    public static WIAGetZarimanCycleVO getZarimanCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetZarimanCycleVO wiaGetZarimanCycleVO = baseJson.getJSONObject("zarimanCycle").toBean(WIAGetZarimanCycleVO.class);
        initTranslateAll(wiaGetZarimanCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetZarimanCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetZarimanCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetZarimanCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetZarimanCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetZarimanCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetZarimanCycleVO.setEta(s);
        if (wiaGetZarimanCycleVO.getIsCorpus()) {
            wiaGetZarimanCycleVO.setState("Corpus");
            wiaGetZarimanCycleVO.setNextState("Grineer");
        } else {
            wiaGetZarimanCycleVO.setState("Grineer");
            wiaGetZarimanCycleVO.setNextState("Corpus");
        }
        return wiaGetZarimanCycleVO;
    }

    /**
     * 获取双衍王境平原时间
     * @return String
     */
    public static WIAGetDuviriCycleVO getDuviriCycle(JSONObject baseJson, List<String> wfDistDTOEnList, Map<String, String> wfDistDTOZhMap) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        WIAGetDuviriCycleVO wiaGetDuviriCycleVO = baseJson.getJSONObject("duviriCycle").toBean(WIAGetDuviriCycleVO.class);
        initTranslateAll(wiaGetDuviriCycleVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetDuviriCycleVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetDuviriCycleVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetDuviriCycleVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetDuviriCycleVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetDuviriCycleVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetDuviriCycleVO.setEta(s);
        if (wiaGetDuviriCycleVO.getState().equals("喜悦")) {
            wiaGetDuviriCycleVO.setNextState("愤怒");
        } else if (wiaGetDuviriCycleVO.getState().equals("愤怒")) {
            wiaGetDuviriCycleVO.setNextState("嫉妒");
        } else if (wiaGetDuviriCycleVO.getState().equals("嫉妒")) {
            wiaGetDuviriCycleVO.setNextState("悲伤");
        } else if (wiaGetDuviriCycleVO.getState().equals("悲伤")) {
            wiaGetDuviriCycleVO.setNextState("恐惧");
        } else if (wiaGetDuviriCycleVO.getState().equals("恐惧")) {
            wiaGetDuviriCycleVO.setNextState("喜悦");
        }
        return wiaGetDuviriCycleVO;
    }

    /**
     * 获取舰队
     * @return String
     */
    public static WIAGetConstructionProgressVO getConstructionProgress() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetConstructionProgressVO wiaGetConstructionProgressVO = baseJson.getJSONObject("constructionProgress").toBean(WIAGetConstructionProgressVO.class);
        initTranslateAll(wiaGetConstructionProgressVO, wfDistDTOEnList, wfDistDTOZhMap);
        return wiaGetConstructionProgressVO;
    }

    /**
     * 获取电波任务
     * @return WIAGetNightwaveVO
     */
    public static WIAGetNightwaveVO getNightwave() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetNightwaveVO wiaGetNightwaveVO = baseJson.getJSONObject("nightwave").toBean(WIAGetNightwaveVO.class);
        initTranslateAll(wiaGetNightwaveVO, wfDistDTOEnList, wfDistDTOZhMap);
        List<WIAGetNightwaveVO.ActiveChallenge> wiaGetNightwaveVOActiveChallenges = wiaGetNightwaveVO.getActiveChallenges();
        for (WIAGetNightwaveVO.ActiveChallenge wiaGetNightwaveVOActiveChallenge : wiaGetNightwaveVOActiveChallenges) {
            wiaGetNightwaveVOActiveChallenge.setActivation(DateUtil.format(DateUtil.parse(wiaGetNightwaveVOActiveChallenge.getActivation()), "yyyy-MM-dd HH:mm:ss"));
            wiaGetNightwaveVOActiveChallenge.setExpiry(DateUtil.format(DateUtil.parse(wiaGetNightwaveVOActiveChallenge.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
            String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetNightwaveVOActiveChallenge.getExpiry()), BetweenFormatter.Level.SECOND);
            wiaGetNightwaveVOActiveChallenge.setEta(s);
        }
        return wiaGetNightwaveVO;
    }

    /**
     * 获取执行官猎杀任务
     * @return WIAGetArchonHuntVO
     */
    public static WIAGetArchonHuntVO getArchonHunt() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetArchonHuntVO wiaGetArchonHuntVO = baseJson.getJSONObject("archonHunt").toBean(WIAGetArchonHuntVO.class);
        initTranslateAll(wiaGetArchonHuntVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetArchonHuntVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetArchonHuntVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetArchonHuntVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetArchonHuntVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetArchonHuntVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetArchonHuntVO.setEta(s);
        return wiaGetArchonHuntVO;
    }

    /**
     * 获取入侵任务
     * @return WIAGetInvasionsVO
     */
    public static List<WIAGetInvasionsVO> getInvasions() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        List<WIAGetInvasionsVO> wiaGetInvasionsVOList = baseJson.getJSONArray("invasions").toList(WIAGetInvasionsVO.class);
        for (WIAGetInvasionsVO wiaGetInvasionsVO : wiaGetInvasionsVOList) {
            initTranslateAll(wiaGetInvasionsVO, wfDistDTOEnList, wfDistDTOZhMap);
        }
        return wiaGetInvasionsVOList;
    }

    /**
     * 获取钢铁之路轮换物品
     * @return WIAGetSteelPathVO
     */
    public static WIAGetSteelPathVO getSteelPath() throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        JSONObject baseJson = getBaseJson();
        List<WfDictDTO> wfDictDTOList = getDist();
        List<String> wfDistDTOEnList = wfDictDTOList.stream().map(WfDictDTO::getEn).toList();
        Map<String, String> wfDistDTOZhMap = wfDictDTOList.stream()
                .collect(Collectors.toMap(WfDictDTO::getEn, WfDictDTO::getZh, (a1, a2) -> a1));
        WIAGetSteelPathVO wiaGetSteelPathVO = baseJson.getJSONObject("steelPath").toBean(WIAGetSteelPathVO.class);
        initTranslateAll(wiaGetSteelPathVO, wfDistDTOEnList, wfDistDTOZhMap);
        wiaGetSteelPathVO.setActivation(DateUtil.format(DateUtil.parse(wiaGetSteelPathVO.getActivation()), "yyyy-MM-dd HH:mm:ss"));
        wiaGetSteelPathVO.setExpiry(DateUtil.format(DateUtil.parse(wiaGetSteelPathVO.getExpiry()), "yyyy-MM-dd HH:mm:ss"));
        String s = DateUtil.formatBetween(DateUtil.date(), DateUtil.parse(wiaGetSteelPathVO.getExpiry()), BetweenFormatter.Level.SECOND);
        wiaGetSteelPathVO.setEta(s);
        return wiaGetSteelPathVO;
    }
}
